package com.lsfb.light.Utils;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lsfb.light.R;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.LsfbAppManager;
import com.zgscwjm.lsfbbasetemplate.utils.DensityUtils;
import com.zgscwjm.lsfbbasetemplate.view.titlebar.LsfbTitleBar;

/**
 * Created by Administrator on 2018/4/23 0023.
 */

public class TitleUtils {

    /**
     * titlebar
     *
     * @param activity
     * @param title
     * @return
     */
    public static LsfbTitleBar setsimpletitlebar(LsfbActivity activity, String title, boolean isBack) {
        LsfbTitleBar titleBar = activity.getTitleBar();
        ImageView back = backbtn2(activity);
        titleBar.setTitleText(title, 18, activity.getResources().getColor(R.color.white_color));
        titleBar.setTitleBarColor(activity.getResources().getColor(R.color.theme_color));
        activity.settitleBarHeight(DensityUtils.dp2px(activity, 52));
        if (isBack) {
            // 标题左侧返回键
            titleBar.setLeftView(back, DensityUtils.dp2px(activity, 5), 0, 0, 0);
        }
        titleBar.showTitlebarLine(View.VISIBLE);
//        titleBar.setLeftImg(R.drawable.img_ngt_back);
        return titleBar;
    }

    /**
     * title右侧的文字按钮
     *
     * @param context
     * @param editstring
     * @return
     */
    public static TextView rightbtn(Context context, String editstring) {
        TextView textView = new TextView(context);
        textView.setText(editstring);
        textView.setTextColor(context.getResources().getColor(R.color.white_color));
        textView.setPadding(DensityUtils.dp2px(context, 20), DensityUtils.dp2px(context, 10), 0, DensityUtils.dp2px(context, 10));
        textView.setTextSize(16);
        return textView;
    }

    /**
     * title左侧的图片按钮
     *
     * @param context
     * @return
     */
    public static ImageView backbtn2(final Activity context) {
        ImageView imageView = new ImageView(context);
        imageView.setImageResource(R.mipmap.img_back);
//        imageView.setImageResource(R.drawable.svg_back1);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(DensityUtils.dp2px(context, 30), DensityUtils.dp2px(context, 30));
        //marginLeft
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);//定义一个LayoutParams
        layoutParams.setMargins(16, 0, 0, 0);    //4个参数按顺序分别是左上右下
        imageView.setLayoutParams(layoutParams);
        //marginLeft
        imageView.setLayoutParams(params);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                LsfbAppManager.getAppManager().finishActivity(context.getClass());
            }
        });
        return imageView;
    }

    public static String getActivityName(Context context) {
        String contextString = context.toString();
        contextString = contextString.toString().substring(contextString.lastIndexOf(".") + 1, contextString.indexOf("@"));
        return contextString;

    }

}
